# Maintainer: J. Peter Mugaas <jpmugaas@suddenlink.net>

_realname=oslo-config
pkgbase=mingw-w64-python-${_realname}
pkgname=( "${MINGW_PACKAGE_PREFIX}-python-${_realname}")
provides=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
conflicts=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
replaces=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
pkgver=8.0.2
pkgrel=1
pkgdesc="parsing command line arguments and .ini style configuration files (mingw-w64)"
arch=('any')
url="https://pypi.python.org/pypi/oslo.config"
license=('Apache')
depends=("${MINGW_PACKAGE_PREFIX}-python"
         "${MINGW_PACKAGE_PREFIX}-python-six"
         "${MINGW_PACKAGE_PREFIX}-python-netaddr"
         "${MINGW_PACKAGE_PREFIX}-python-stevedore"
         "${MINGW_PACKAGE_PREFIX}-python-debtcollector"
         "${MINGW_PACKAGE_PREFIX}-python-oslo-i18n"
         "${MINGW_PACKAGE_PREFIX}-python-rfc3986"
         "${MINGW_PACKAGE_PREFIX}-python-yaml")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-setuptools")
checkdepends=("${MINGW_PACKAGE_PREFIX}-python-oslotest"
              "${MINGW_PACKAGE_PREFIX}-python-sphinx"
              "${MINGW_PACKAGE_PREFIX}-python-testrepository"
              "${MINGW_PACKAGE_PREFIX}-python-oslo-log")
options=('staticlibs' 'strip' '!debug')
install=${_realname}3-${CARCH}.install
source=("${_realname}-${pkgver}.tar.gz::https://github.com/openstack/oslo.config/archive/${pkgver}.tar.gz")
sha512sums=('67ffdf44097da4ffc92323609bd9ae967029ee46498f7b656018aaa876b05d3e7cd24e9c7e1116cc0ce2aaa10125cc5ae8a652b579261d2842b19032bae3c782')

prepare() {
  cd "${srcdir}/oslo.config-${pkgver}"
  sed -i '/argparse/d' requirements.txt

  # Set version for setuptools_scm
  export SETUPTOOLS_SCM_PRETEND_VERSION=${pkgver}
  export PBR_VERSION=${pkgver}
}

build() {
  cd "${srcdir}/oslo.config-${pkgver}"
  ${MINGW_PREFIX}/bin/python setup.py build
}

check() {
  cd "${srcdir}/oslo.config-${pkgver}"
  ${MINGW_PREFIX}/bin/python setup.py testr
}

package() {
  cd "${srcdir}/oslo.config-${pkgver}"
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python setup.py install --prefix=${MINGW_PREFIX} \
    --root="${pkgdir}" --optimize=1 --skip-build

  install -Dm644 LICENSE "${pkgdir}${MINGW_PREFIX}/share/licenses/python-${_realname}/LICENSE"

  local PREFIX_WIN=$(cygpath -wm ${MINGW_PREFIX})
  # fix python command in files
  for _f in "${pkgdir}${MINGW_PREFIX}"/bin/*.py; do
    sed -e "s|/usr/bin/env |${MINGW_PREFIX}|g" \
        -e "s|${PREFIX_WIN}|${MINGW_PREFIX}|g" -i ${_f}
  done
}
